package ace.j2se.l3;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;

public class TestLink {
	public static void main(String[] args) {
//		T t1 = new T();
//		t1.run();
		LoginTest lt =new LoginTest();
		lt.login();
	}

}

class T implements Runnable {
	static LoginTest lt = new LoginTest();

	public void run() {
		for (int i = 0; i < 100; i++) {
			try {
				Thread.sleep(500);
				lt.login();
			} catch (InterruptedException e) {
				Thread.interrupted();
			}
		}
	}
}

class LoginTest {
	void login() {
		try {
			URL url = new URL(
					"http://10.1.21.116:8080/pv/j_acegi_security_check");
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			OutputStreamWriter out = new OutputStreamWriter(
					connection.getOutputStream(), "utf-8");
			out.write("j_username=admin&j_password=123456");
			// remember to clean up
			out.flush();
			out.close();
			InputStream in = connection.getInputStream();
			// byte[]buf=new byte[1024];
			// while(in.read(buf)>-1){
			// System.out.print(new String(buf));
			// }
			in.close();
			Date now = new Date();
			// System.out.println(now.getTime()+"成功");

			URL url2 = new URL(
					"http://10.1.21.116:8080/pv/pages/search/searchCaseWithImageBySelfPermission.action");
			connection = url2.openConnection();
			// connection.setDoOutput(true);
			in = connection.getInputStream();
			byte[] buf = new byte[1024];
			while (in.read(buf) > -1) {
				System.out.println(buf);
				for(int i=0;i<buf.length;i++){
					System.out.println(buf[i]);
				}
				System.out.println(new String(buf));
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
